const model = require('../models/wearModel');

var wearModel = model.wearModel;

async function findImages(type) {
    try {
        var data = await wearModel.find({type:type});
        if (data) {
            return {
                success: true,
                imgData:data
            }
        } else {
            return {
                success: false,
                msg:'error!'
            }
        }
    } catch (error) {
        return {
            success: false,
            msg:'the database error!'+error
        }
    }
}

async function findNumIma(type) {
    try {
        var data = await wearModel.find({ type: type },).limit(10);
        if (data) {
            return {
                success: true,
                imgData: data
            }
        } else {
            return {
                success: false,
                msg: 'error!'
            }
        }
    } catch (error) {
        return {
            success: false,
            msg: 'the database error!' + error
        }
    }
}

exports.findImages = findImages;
exports.findNumIma = findNumIma;